import yaml, os, allure
#yaml 文件主要存储测试数据，进行测试用例的参数化使用
@allure.step("读取当前yaml文件测试数据")
def get_yaml_data(yamlpath):
    f = open(yamlpath, "r", encoding="utf-8")
    yamlpath = f.read()
    print(yamlpath)
    d = yaml.load(yamlpath,Loader=yaml.CFullLoader)   #数据转字典
    # print(d["test_url_params"][0][0]["mock_url"])
    f.close()
    return d

@allure.step("获取当前目录路径，拼接yaml路径")
def get_yaml_path():
    curpath = os.path.dirname(os.path.realpath(__file__))
    print("当前路径：", curpath)
    yamlpath = os.path.join(curpath, "test_data.yml")  # 拼接路径与文件名
    print(yamlpath)
    return yamlpath


yamlpath = get_yaml_path()
test_data = get_yaml_data(yamlpath)
print(test_data["test_url_params"][0][0]["mock_url"])